package com.atjava.webspider.gui.data;

import java.awt.Color;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import com.atjava.webspider.model.Task;
import com.atjava.webspider.util.DialogUtil;
import com.atjava.webspider.util.FileSystemUtil;

public class DataViewGui extends JDialog {

	private static final long serialVersionUID = 1L;
	
	private JPanel jContentPane = null;
	private JLabel jLabel1 = null;
	private JLabel jLabel2 = null;
	private JLabel jLabel3 = null;
	private JButton jButtonReset = null;
	private JTextArea jTextAreaData = null;
	
	private JScrollPane jScrollPane = null;
	private Task task;
	private File file;
	private JLabel jLabelTask = null;
	private JLabel jLabelFile = null;
	/**
	 * @param owner
	 */
	public DataViewGui(JDialog owner,boolean modal,Task task,File file) {
		super(owner,modal);
		this.task = task;
		this.file = file;
		initialize();
		setTextValue();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setBounds(new Rectangle(0, 0, 700, 500));
		this.setResizable(false);
		this.setTitle("数据查看");
		this.setLocationRelativeTo(getOwner());
		this.setContentPane(getJContentPane());
	}
	
	private void setTextValue(){
		try {
			jLabelTask.setText(task.getName());
			jLabelFile.setText(file.getAbsolutePath());
			FileSystemUtil fsu = new FileSystemUtil();
			String text = fsu.readText(file.getAbsolutePath());
			jTextAreaData.setText(text);
		} catch (Exception e) {
			e.printStackTrace();
			DialogUtil.showError(this, "加载数据失败！");
		}
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabelFile = new JLabel();
			jLabelFile.setBounds(new Rectangle(75, 25, 610, 20));
			jLabelTask = new JLabel();
			jLabelTask.setBounds(new Rectangle(75, 5, 610, 20));
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(10, 45, 65, 20));
			jLabel1.setText("数据内容：");
			jLabel2 = new JLabel();
			jLabel2.setBounds(new Rectangle(10, 25, 65, 20));
			jLabel2.setText("文件信息：");
			jLabel3 = new JLabel();
			jLabel3.setBounds(new Rectangle(10, 5, 65, 20));
			jLabel3.setText("任务名称：");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(jLabel1, null);
			jContentPane.add(jLabel2, null);
			jContentPane.add(jLabel3, null);
			jContentPane.add(getJButtonReset(), null);
			jContentPane.add(getJScrollPane(), null);
			jContentPane.add(jLabelTask, null);
			jContentPane.add(jLabelFile, null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jButtonReset	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonReset() {
		if (jButtonReset == null) {
			jButtonReset = new JButton();
			jButtonReset.setBounds(new Rectangle(300, 441, 70, 25));
			jButtonReset.setText("关闭");
			jButtonReset.addMouseListener(new MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					DataViewGui.this.setVisible(false);
				}
			});
		}
		return jButtonReset;
	}

	/**
	 * This method initializes jTextAreaData	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	private JTextArea getJTextFieldData() {
		if (jTextAreaData == null) {
			jTextAreaData = new JTextArea();
			jTextAreaData.setForeground(new Color(0, 0, 204));
			jTextAreaData.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		}
		return jTextAreaData;
	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(new Rectangle(10, 65, 675, 370));
			jScrollPane.setViewportView(getJTextFieldData());
		}
		return jScrollPane;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"
